//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.aidong.web.controller.member;

import com.aidong.cache.NameItem;
import com.aidong.dao.wills.CardManyUserDao;
import com.aidong.dao.wills.CardTypeCodeDao;
import com.aidong.dao.wills.DicShopAreaCodeDao;
import com.aidong.dao.wills.MemberContractDao;
import com.aidong.model.wills.CardManyUser;
import com.aidong.model.wills.CardTypeCode;
import com.aidong.model.wills.DicShopCode;
import com.aidong.model.wills.MemberCard;
import com.aidong.model.wills.MemberContract;
import com.aidong.model.wills.MemberEarnest;
import com.aidong.model.wills.MemberInfo;
import com.aidong.model.wills.PayList;
import com.aidong.model.wills.Upload;
import com.aidong.service.UploadService;
import com.aidong.web.controller.member.PayController;
import java.io.ByteArrayOutputStream;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import jxl.Sheet;
import jxl.Workbook;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping({"memberContractAdd2"})
public class MemberContractAdd2Controller extends PayController {
    @Resource
    MemberContractDao memberContractDao;
    @Resource
    CardTypeCodeDao cardTypeCodeDao;
    @Resource
    CardManyUserDao cardManyUserDao;
    @Resource
    DicShopAreaCodeDao dicShopAreaCodeDao;
    @Resource
    UploadService uploadService;

    public MemberContractAdd2Controller() {
    }

    @RequestMapping({"add"})
    public ModelAndView add() {
        List promotionList = this.promotionDao.getShopPromotionList(this.getLoginShopCode());
        ModelAndView mv = new ModelAndView("member/contract/add2");
        mv.addObject("promotionList", promotionList);
        mv.addObject("gender", this.getTypeList("gender"));
        mv.addObject("idType", this.getTypeList("idType"));
        mv.addObject("_picPath", this.getSetting("pic.path"));
        mv.addObject("_oper", "add");
        return mv;
    }

    @RequestMapping({"_add"})
    @ResponseBody
    public String _add(@ModelAttribute("contract") MemberContract contract, @RequestParam(value = "shops",required = false) String shops, @RequestParam("mbls") String mbls, @RequestParam("payls") String payls, HttpServletRequest request) {
        if(this.chkNull(contract.getSaleType())) {
            return this.getResult(false, "请选择销售类型");
        } else if(this.chkNull(contract.getCardType())) {
            return this.getResult(false, "请选择会籍类型");
        } else if(this.chkNull(contract.getFactPrice())) {
            return this.getResult(false, "请输入实际售价");
        } else {
            contract.setInAmount(Double.valueOf(0.0D));
            if(!"1".equals(contract.getSaleType())) {
                if(!"2".equals(contract.getSaleType()) && !"3".equals(contract.getSaleType())) {
                    return this.getResult(false, "销售类型错误");
                }

                if(this.chkNull(contract.getOldContractCode())) {
                    return this.getResult(false, "请输入原合同编号");
                }

                MemberContract cardType = this.memberContractDao.getByContractCode(contract.getOldContractCode());
                if(cardType == null) {
                    return this.getResult(false, "原合同编号错误");
                }

                if(cardType.getBeginTime() == null || cardType.getEndTime() == null || cardType.getStatus().intValue() != 1 || cardType.getEffectiveDate() != null || "8".equals(cardType.getSaleType())) {
                    return this.getResult(false, "原合同无效");
                }

                if("2".equals(contract.getSaleType())) {
                    if(cardType.getEndTime().getTime() < System.currentTimeMillis()) {
                        return this.getResult(false, "原合同已过有效期");
                    }

                    if(System.currentTimeMillis() - cardType.getBeginTime().getTime() < 2678400000L && contract.getStatus() != null && contract.getStatus().intValue() == 2) {
                        contract.setInAmount(cardType.getFactPrice());
                    } else {
                        double cardPrice;
                        if(cardType.getTotalCount().intValue() > 0) {
                            cardPrice = (double)Math.round((double)cardType.getRestCount().intValue() * cardType.getFactPrice().doubleValue() / (double)cardType.getTotalCount().intValue());
                        } else if(cardType.getBeginTime().getTime() > System.currentTimeMillis()) {
                            cardPrice = cardType.getFactPrice().doubleValue();
                        } else {
                            cardPrice = (double)Math.round((double)(cardType.getEndTime().getTime() - System.currentTimeMillis()) * cardType.getFactPrice().doubleValue() / (double)(cardType.getEndTime().getTime() - cardType.getBeginTime().getTime()));
                        }

                        if(cardPrice > cardType.getFactPrice().doubleValue()) {
                            cardPrice = cardType.getFactPrice().doubleValue();
                        }

                        contract.setInAmount(Double.valueOf(cardPrice > 0.0D?cardPrice:0.0D));
                    }
                }
            }

            CardTypeCode var20 = (CardTypeCode)this.cardTypeCodeDao.getById(contract.getCardType());
            if(var20 == null) {
                return this.getResult(false, "没有这个会籍类型");
            } else {
                Double var23 = null;
                if(!this.chkNullZ(contract.getEarnestId())) {
                    MemberEarnest fixedFee = (MemberEarnest)this.memberEarnestDao.getById(contract.getEarnestId());
                    if(fixedFee == null || fixedFee.getStatus().intValue() != 0 || !fixedFee.getShopCode().equalsIgnoreCase(this.getLoginShopCode())) {
                        return this.getResult(false, "定金不可用");
                    }

                    contract.setEarnestAmount(fixedFee.getEarnestAmount());
                    if(fixedFee.getOverDueUse().intValue() == 0 && var20.getCode().equalsIgnoreCase(fixedFee.getCardType())) {
                        var23 = fixedFee.getCardPrice();
                    }
                } else {
                    contract.setEarnestId((Integer)null);
                    contract.setEarnestAmount(Double.valueOf(0.0D));
                }

                if(this.chkNullZ(var23)) {
                    if((this.chkNullZ(contract.getPromotionId()) || this.chkNullZ(var20.getPromotionCard())) && (var20.getActiveTime().getTime() > System.currentTimeMillis() || var20.getInactiveTime().getTime() < System.currentTimeMillis())) {
                        return this.getResult(false, "会籍类型不在有效期");
                    }

                    Double var21 = this.cardTypeCodeDao.getCardTypeDiscount(contract.getCardType(), this.getLoginShopCode());
                    if(var21 == null) {
                        return this.getResult(false, "会籍类型不能在本店销售");
                    }

                    var23 = Double.valueOf(var20.getPrice().doubleValue() * var21.doubleValue());
                }

                if(!this.equals(contract.getCardPrice().doubleValue(), var23.doubleValue())) {
                    return this.getResult(false, "卡价格不符");
                } else {
                    contract.setShopCode(this.getLoginShopCode());
                    contract.setSaleDate(new Date());
                    if(var20.getAddValids().intValue() > 0) {
                        Calendar var22 = Calendar.getInstance();
                        var22.setTime(contract.getEndTime());
                        if("01".equals(var20.getAddValidUnit())) {
                            var22.add(5, var20.getAddValids().intValue());
                        } else if("02".equals(var20.getAddValidUnit())) {
                            var22.add(5, var20.getAddValids().intValue() * 7);
                        }

                        if("03".equals(var20.getAddValidUnit())) {
                            var22.add(2, var20.getAddValids().intValue());
                        }

                        if("04".equals(var20.getAddValidUnit())) {
                            var22.add(1, var20.getAddValids().intValue());
                        }

                        contract.setNewEndTime(var22.getTime());
                    }

                    contract.setTotalCount(var20.getDegree());
                    contract.setRestCount(var20.getDegree());
                    contract.setManyShop(var20.getManyShop());
                    contract.setValids(var20.getValids());
                    contract.setValidUnit(var20.getValidUnit());
                    contract.setAddValids(var20.getAddValids());
                    contract.setAddValidUnit(var20.getAddValidUnit());
                    contract.setAddFee(Double.valueOf(0.0D));
                    contract.setStopFee(var20.getStopFee());
                    contract.setChangeFee(var20.getChangeFee());
                    contract.setMendFee(var20.getMendFee());
                    contract.setChgShopFee(var20.getChgShopFee());
                    contract.setContDiscount(var20.getContDiscount());
                    contract.setStatus(Integer.valueOf(this.equals(contract.getFactPrice().doubleValue(), contract.getTotalPrice().doubleValue())?1:2));
                    contract.setCommissionDate(new Date());
                    contract.setReceivePaper(Integer.valueOf(0));
                    contract.setBarcodeTasteContract(Integer.valueOf(0));
                    contract.setSignStatus(Integer.valueOf(this.chkNullZ(contract.getSignStatus())?2:0));
                    contract.setPrintLabel(Integer.valueOf(0));
                    contract.setCreateUser(this.getLoginUserCode());
                    contract.setCreateTime(new Date());
                    contract.setUpdateTime(new Date());
                    contract.setReviewStatus(Integer.valueOf(1));
                    if(!this.chkNull(var20.getGiftCardType()) && contract.getStatus().intValue() == 1 && !this.chkNull(contract.getGiftCardCode())) {
                        NameItem var24 = this.cache.getNameItem("giftCardType", var20.getGiftCardType());
                        if(var24 != null) {
                            contract.setGiftCardType(var24.getId());
                            if(contract.getGiftCardCode().length() <= 6) {
                                contract.setGiftCardCode("9900119000100" + contract.getGiftCardCode());
                            }

                            contract.setGiftCardAmount(this.parseDouble(var24.getProp()));
                        }
                    }

                    double var25 = 0.0D;
                    if(contract.getGiftCardAmount() != null) {
                        var25 += contract.getGiftCardAmount().doubleValue();
                    }

                    if(var20.getAmortizeFee2() != null) {
                        var25 += var20.getAmortizeFee2().doubleValue();
                    }

                    if(var20.getAmortizeFee3() != null) {
                        var25 += var20.getAmortizeFee3().doubleValue();
                    }

                    if(var20.getAmortizeFee4() != null) {
                        var25 += var20.getAmortizeFee4().doubleValue();
                    }

                    contract.setFixedFee(Double.valueOf(var25));
                    double giftFee = 0.0D;
                    if(contract.getGiftCardAmount() != null) {
                        giftFee += contract.getGiftCardAmount().doubleValue();
                    }

                    if(var20.getAmortizeFee2() != null) {
                        giftFee += var20.getAmortizeFee2().doubleValue();
                    }

                    if(var20.getAmortizeFee3() != null) {
                        giftFee += var20.getAmortizeFee3().doubleValue();
                    }

                    if(var20.getAmortizeFee4() != null) {
                        giftFee += var20.getAmortizeFee4().doubleValue();
                    }

                    if(giftFee > 0.0D) {
                        DecimalFormat shopList = new DecimalFormat("0.##");
                        StringBuilder memberList = new StringBuilder();
                        memberList.append("上述会费还包含价值人民币" + shopList.format(giftFee) + "元的礼包，含：" + (this.chkNullZ(contract.getGiftCardAmount())?"---":shopList.format(contract.getGiftCardAmount())) + "元的威尔士礼品卡，" + (this.chkNullZ(var20.getAmortizeFee4())?"---":shopList.format(var20.getAmortizeFee4())) + "元的赠品，" + (this.chkNullZ(var20.getAmortizeFee2())?"---":shopList.format(var20.getAmortizeFee2())) + "元的健身计划，" + (this.chkNullZ(var20.getAmortizeFee3())?"---":shopList.format(var20.getAmortizeFee3())) + "元的PT课程。");
                        contract.setGiftNote(memberList.toString());
                    }

                    ArrayList var26 = new ArrayList();
                    if(!this.chkNull(shops)) {
                        String[] var27 = shops.split(",");
                        String[] member = var27;
                        int payList = var27.length;

                        for(int payMsg = 0; payMsg < payList; ++payMsg) {
                            String pay = member[payMsg];
                            if(!this.chkNull(pay)) {
                                var26.add(pay.trim());
                            }
                        }
                    }

                    List var28 = (List)request.getSession().getAttribute("contract_add2_list");
                    if(var28 != null && var28.size() != 0) {
                        MemberInfo var29 = (MemberInfo)var28.get(0);
                        if(var29 == null) {
                            return this.getResult(false, "会员信息错误");
                        } else {
                            Iterator var30 = var28.iterator();

                            while(var30.hasNext()) {
                                MemberInfo var32 = (MemberInfo)var30.next();
                                if(this.memberBlackListDao.chkExists(var29.getIdType(), var29.getIdNumber())) {
                                    return this.getFail(-8, "证件号在黑名单中，不能办理合同");
                                }

                                if(var32.getStatus().intValue() == 1) {
                                    if(this.chkNull(var32.getCardCode())) {
                                        return this.getResult(false, "会员卡号错误");
                                    }

                                    MemberCard var34 = this.memberCardDao.getById(var32.getCardCode());
                                    if(var34 == null || !var34.getShopCode().equalsIgnoreCase(this.getLoginShopCode()) || var34.getStatus().intValue() != 1) {
                                        return this.getResult(false, "会员卡号错误");
                                    }
                                }

                                if(this.chkNull(var32.getMemberCode())) {
                                    MemberInfo var35 = this.memberInfoDao.getByIdNumber(var32.getIdType(), var32.getIdNumber());
                                    if(var35 != null) {
                                        if(!var32.getChName().equalsIgnoreCase(var35.getChName())) {
                                            return this.getResult(false, "姓名和证件号不一致和原有会员信息不一致");
                                        }

                                        var32.setMemberCode(var35.getMemberCode());
                                    }
                                }
                            }

                            contract.setCardCode(var29.getCardCode());
                            ArrayList var31 = new ArrayList();
                            StringBuilder var33 = new StringBuilder();
                            PayList var36 = this.getPayList(payls, var31, "01", var33);
                            if(var36 == null) {
                                return this.getResult(false, var33.toString());
                            } else if(!this.equals(var36.getAmount().doubleValue(), contract.getPayAmount().doubleValue())) {
                                return this.getResult(false, "付款金额不一致");
                            } else {
                                contract.setSalesCode(var36.getSalesCode());
                                contract.setSalesCode2(var36.getSalesCode2());

                                try {
                                    this.memberContractDao.addContract(contract, var26, var28, var31);
                                    String e = !this.chkNull(contract.getGiftCardType()) && !this.chkNull(contract.getGiftCardCode())?"5":"1";
                                    this.smsListService.addSmsList(e + contract.getSaleType(), contract.getSaleId().intValue());
                                    this.addUserLog("会籍合同销售", "合同号:" + contract.getContractCode() + ",会员:" + contract.getMemberCode());
                                } catch (Exception var19) {
                                    this.log.error("add membercontract", var19);
                                    return this.getResult(false, "保存发生错误");
                                }

                                return this.getResult(true, "保存完成");
                            }
                        }
                    } else {
                        return this.getResult(false, "请先上传会员信息");
                    }
                }
            }
        }
    }

    @RequestMapping({"getCardTypeList"})
    @ResponseBody
    public String getCardTypeList(@RequestParam("saleType") Integer saleType, @RequestParam("op") String op) {
        int option = 0;
        if(!this.chkNull(op)) {
            if(op.indexOf("r") >= 0) {
                ++option;
            }

            if(op.indexOf("p") >= 0) {
                option += 2;
            }
        }

        List list = this.cardTypeCodeDao.getShopCardTypeList(this.getLoginShopCode(), saleType.intValue(), option);
        StringBuilder sb = new StringBuilder();
        sb.append("[");

        CardTypeCode cardType;
        for(Iterator i$ = list.iterator(); i$.hasNext(); sb.append("{code:\"").append(cardType.getCode()).append("\"").append(",name:\"").append(cardType.getChName()).append("\"").append("}")) {
            cardType = (CardTypeCode)i$.next();
            if(sb.length() > 5) {
                sb.append(",");
            }
        }

        sb.append("]");
        return this.getSuccess(sb.toString(), "");
    }

    @RequestMapping({"getCardType"})
    @ResponseBody
    public String getCardType(@RequestParam("code") String code, @RequestParam(value = "pmId",required = false) Integer pmId, @RequestParam(value = "earnestId",required = false) Integer earnestId) {
        CardTypeCode cardType = (CardTypeCode)this.cardTypeCodeDao.getById(code);
        if(cardType == null) {
            return this.getResult(false, "没有这个卡种");
        } else {
            Double cardPrice = null;
            if(!this.chkNullZ(earnestId)) {
                MemberEarnest pnum = (MemberEarnest)this.memberEarnestDao.getById(earnestId);
                if(pnum == null || pnum.getStatus().intValue() != 0 || !"1".equals(pnum.getEarnestType()) || !pnum.getShopCode().equalsIgnoreCase(this.getLoginShopCode())) {
                    return this.getResult(false, "没有这个定金");
                }

                if(pnum.getOverDueUse().intValue() == 0 && cardType.getCode().equalsIgnoreCase(pnum.getCardType())) {
                    cardPrice = pnum.getCardPrice();
                }
            }

            if(this.chkNullZ(cardPrice)) {
                if((this.chkNullZ(pmId) || this.chkNullZ(cardType.getPromotionCard())) && (cardType.getActiveTime().getTime() > System.currentTimeMillis() || cardType.getInactiveTime().getTime() < System.currentTimeMillis())) {
                    return this.getResult(false, "不在有效期");
                }

                Double var13 = this.cardTypeCodeDao.getCardTypeDiscount(code, this.getLoginShopCode());
                if(var13 == null) {
                    return this.getResult(false, "不能在本店销售");
                }

                cardPrice = Double.valueOf(cardType.getPrice().doubleValue() * var13.doubleValue());
            }

            int var14 = 1;
            if(cardType.getManyUser().intValue() == 1) {
                List giftCard = this.cardManyUserDao.getCardManyUserList(code);
                var14 = 0;

                CardManyUser shopList;
                for(Iterator sb = giftCard.iterator(); sb.hasNext(); var14 += shopList.getUseQuantity().intValue()) {
                    shopList = (CardManyUser)sb.next();
                }
            }

            NameItem var15 = null;
            if(!this.chkNull(cardType.getGiftCardType())) {
                var15 = this.cache.getNameItem("giftCardType", cardType.getGiftCardType());
            }

            StringBuilder var16 = new StringBuilder();
            var16.append("{code:\"").append(cardType.getCode()).append("\"").append(",name:\"").append(cardType.getChName()).append("\"").append(",valids:").append(cardType.getValids()).append("").append(",validUnit:\"").append(cardType.getValidUnit()).append("\"").append(",valid:\"").append(cardType.getValids() + this.nvl(this.cache.getValue("timeUnit", cardType.getValidUnit()))).append("\"").append(",addValids:").append(cardType.getAddValids()).append("").append(",addValidUnit:\"").append(cardType.getAddValidUnit()).append("\"").append(",addValid:\"").append(cardType.getAddValids() + this.nvl(this.cache.getValue("timeUnit", cardType.getAddValidUnit()))).append("\"").append(",openPeriod:").append(cardType.getOpenPeriod()).append("").append(",cardPrice:").append(cardPrice).append("").append(",userNum:").append(var14).append("").append(",giftCardType:\"").append(var15 == null?"":var15.getId()).append("\"").append(",giftCardName:\"").append(var15 == null?"":var15.getName()).append("\"").append(",giftCardAmount:\"").append(var15 == null?"":var15.getProp()).append("\"").append(",manyShop:\"").append(this.nvl(cardType.getManyShop()).trim()).append("\"").append(",manyShopQuantity:").append(cardType.getManyShopQuantity()).append("").append(",shopList:[");
            if(!this.chkNull(cardType.getManyShop())) {
                List var17 = this.dicShopAreaCodeDao.getAreaShopList(cardType.getManyShop(), false);
                int sn = 0;
                Iterator i$ = var17.iterator();

                while(i$.hasNext()) {
                    DicShopCode shop = (DicShopCode)i$.next();
                    if(shop.getStatus().intValue() == 1) {
                        if(sn++ > 0) {
                            var16.append(",");
                        }

                        var16.append("{code:\"").append(shop.getCode()).append("\"").append(",name:\"").append(shop.getChName()).append("\"").append("}");
                    }
                }
            }

            var16.append("]}");
            return this.getSuccess(var16.toString(), "");
        }
    }

    @RequestMapping({"_upload"})
    @ResponseBody
    public String _upload(@RequestParam("file") MultipartFile file, @RequestParam(value = "tp",required = false) String tp, HttpServletRequest request) {
        if("2".equals(tp)) {
            return this._uploadph(file, request);
        } else if(file.isEmpty()) {
            return this.getResult(false, "请上传文件");
        } else {
            String fileName = file.getOriginalFilename();
            String ext = this.getFileExt(fileName);
            if(!"xls".equals(ext) && !"xlsx".equals(ext)) {
                return this.getResult(false, "只能上传Excel文件(xls,xlsx)");
            } else {
                ArrayList list = new ArrayList();

                try {
                    Workbook e = Workbook.getWorkbook(file.getInputStream());
                    Sheet st = e.getSheet(0);
                    int n = st.getRows();
                    int i = 1;

                    while(true) {
                        if(i >= n) {
                            e.close();
                            break;
                        }

                        String cardCode = this.trim(st.getCell(0, i).getContents());
                        String name = this.trim(st.getCell(1, i).getContents());
                        String idType = this.trim(st.getCell(2, i).getContents());
                        if(!this.chkNull(cardCode)) {
                            if("身份证".equals(idType)) {
                                idType = "1";
                            } else if("护照".equals(idType)) {
                                idType = "2";
                            } else {
                                if(!"回乡证".equals(idType)) {
                                    return this.getResult(false, "证件类型错误-" + idType);
                                }

                                idType = "3";
                            }

                            String idNumber = this.trim(st.getCell(3, i).getContents());
                            String gender = this.trim(st.getCell(4, i).getContents());
                            if("男".equals(gender)) {
                                gender = "M";
                            } else {
                                if(!"女".equals(gender)) {
                                    return this.getResult(false, "性别错误-" + gender);
                                }

                                gender = "F";
                            }

                            String mobile = this.trim(st.getCell(5, i).getContents());
                            if(!this.chkNull(cardCode)) {
                                if(this.memberBlackListDao.chkExists(idType, idNumber)) {
                                    return this.getFail(-8, "证件号" + idNumber + "在黑名单中，不能办理");
                                }

                                if(this.chkNull(name) || this.chkNull(idType) || this.chkNull(idNumber)) {
                                    return this.getResult(false, "第" + (i + 1) + "行数据不全");
                                }

                                MemberInfo member = this.memberInfoDao.getByIdNumber(idType, idNumber);
                                if(member != null) {
                                    if(!member.getChName().equalsIgnoreCase(name)) {
                                        return this.getResult(false, "姓名和证件号不一致和原有会员信息不一致-" + idNumber);
                                    }

                                    member.setStatus(Integer.valueOf(0));
                                    if(this.chkNull(member.getCardCode()) || !cardCode.equalsIgnoreCase(member.getCardCode())) {
                                        member.setCardCode(cardCode);
                                        member.setStatus(Integer.valueOf(1));
                                    }
                                } else {
                                    member = new MemberInfo();
                                    member.setMemberSource("01");
                                    member.setShopCode(this.getLoginShopCode());
                                    member.setCardCode(cardCode);
                                    member.setChName(name);
                                    member.setIdType(idType);
                                    member.setIdNumber(idNumber);
                                    member.setMemberPhoto("");
                                    member.setIdCardPhoto("");
                                    member.setStatus(Integer.valueOf(1));
                                    member.setCreateUser(this.getLoginUserCode());
                                    member.setCreateTime(new Date());
                                    member.setUpdateTime(new Date());
                                }

                                member.setGender(gender);
                                member.setMobile(mobile);
                                if(member.getStatus().intValue() == 1) {
                                    MemberCard card = this.memberCardDao.getById(member.getCardCode());
                                    if(card == null || !card.getShopCode().equalsIgnoreCase(this.getLoginShopCode()) || card.getStatus().intValue() != 1) {
                                        return this.getResult(false, "会员卡号错误-" + member.getCardCode());
                                    }
                                }

                                list.add(member);
                            }
                        }

                        ++i;
                    }
                } catch (Exception var20) {
                    this.log.error("_uploadmb", var20);
                    return this.getResult(false, "文件格式错误");
                }

                if(list.size() == 0) {
                    return this.getResult(false, "没有会员信息");
                } else {
                    request.getSession().setAttribute("contract_add2_list", list);
                    return this.getSuccess(this.getMemberInfo(list), "");
                }
            }
        }
    }

    @RequestMapping({"_uploadph"})
    @ResponseBody
    public String _uploadph(@RequestParam("file") MultipartFile file, HttpServletRequest request) {
        List list = (List)request.getSession().getAttribute("contract_add2_list");
        if(list == null) {
            return this.getResult(false, "请先上传会员信息");
        } else if(file.isEmpty()) {
            return this.getResult(false, "请上传文件");
        } else {
            String fileName = file.getOriginalFilename();
            String ext = this.getFileExt(fileName);
            if(!"zip".equals(ext)) {
                return this.getResult(false, "只能上传zip文件");
            } else {
                try {
                    ZipInputStream e = new ZipInputStream(file.getInputStream());
                    StringBuilder msg = new StringBuilder();
                    byte[] buf = new byte[1024];
                    int tp = 0;

                    while(true) {
                        int n;
                        MemberInfo member;
                        String name;
                        label68:
                        do {
                            ZipEntry entry;
                            if((entry = e.getNextEntry()) == null || entry.isDirectory()) {
                                e.close();
                                return this.getSuccess(this.getMemberInfo(list), "");
                            }

                            name = entry.getName();
                            String pnam = name;
                            n = name.lastIndexOf(".");
                            if(n > 0) {
                                pnam = name.substring(0, n);
                            }

                            member = null;
                            Iterator bos = list.iterator();

                            MemberInfo upload;
                            do {
                                if(!bos.hasNext()) {
                                    continue label68;
                                }

                                upload = (MemberInfo)bos.next();
                            } while(!pnam.equalsIgnoreCase(upload.getCardCode()) && !pnam.equalsIgnoreCase(upload.getIdNumber()));

                            tp = pnam.equalsIgnoreCase(upload.getCardCode())?2:1;
                            member = upload;
                        } while(member == null);

                        ByteArrayOutputStream bos1 = new ByteArrayOutputStream();

                        while((n = e.read(buf)) != -1) {
                            bos1.write(buf, 0, n);
                        }

                        Upload upload1 = this.uploadService.addUpload(name, bos1.toByteArray(), msg);
                        if(upload1 == null) {
                            return this.getResult(false, msg.toString());
                        }

                        if(tp == 2) {
                            member.setMemberPhoto(upload1.getUrl());
                        } else {
                            member.setIdCardPhoto(upload1.getUrl());
                        }
                    }
                } catch (Exception var17) {
                    this.log.error("_uploadph", var17);
                    return this.getResult(false, "文件格式错误");
                }
            }
        }
    }

    private String getMemberInfo(List<MemberInfo> list) {
        StringBuilder sb = new StringBuilder("[");

        MemberInfo member;
        for(Iterator i$ = list.iterator(); i$.hasNext(); sb.append("{cardCode:\"").append(member.getCardCode()).append("\"").append(",memberCode:\"").append(this.nvl(member.getMemberCode())).append("\"").append(",memberName:\"").append(member.getChName()).append("\"").append(",gender:\"").append(member.getGender()).append("\"").append(",genderName:\"").append(this.cache.getValue("gender", member.getGender())).append("\"").append(",idType:\"").append(member.getIdType()).append("\"").append(",idTypeName:\"").append(this.cache.getValue("idType", member.getIdType())).append("\"").append(",idNumber:\"").append(member.getIdNumber()).append("\"").append(",mobile:\"").append(member.getMobile()).append("\"").append(",memberPhoto:\"").append(this.nvl(member.getMemberPhoto())).append("\"").append(",idCardPhoto:\"").append(this.nvl(member.getIdCardPhoto())).append("\"").append("}")) {
            member = (MemberInfo)i$.next();
            if(sb.length() > 2) {
                sb.append(",");
            }
        }

        sb.append("]");
        return sb.toString();
    }

    private String getFileExt(String fileName) {
        if(fileName != null) {
            int pos = fileName.lastIndexOf(".");
            return pos > 0?fileName.substring(pos + 1).toLowerCase():"jpg";
        } else {
            return null;
        }
    }
}
